/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.order;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.order.HkShopUserOrder;
import com.thinkgem.jeesite.modules.hk.shop.service.order.HkShopUserOrderService;

/**
 * 用户订单管理Controller
 * @author 罗天文
 * @version 2018-08-22
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/order/hkShopUserOrder")
public class HkShopUserOrderController extends BaseController {

	@Autowired
	private HkShopUserOrderService hkShopUserOrderService;
	
	@ModelAttribute
	public HkShopUserOrder get(@RequestParam(required=false) String id) {
		HkShopUserOrder entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkShopUserOrderService.get(id);
		}
		if (entity == null){
			entity = new HkShopUserOrder();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:order:hkShopUserOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkShopUserOrder hkShopUserOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkShopUserOrder> page = hkShopUserOrderService.findPage(new Page<HkShopUserOrder>(request, response), hkShopUserOrder); 
		model.addAttribute("page", page);
		return "hk/shop/order/hkShopUserOrderList";
	}

	@RequiresPermissions("shop:order:hkShopUserOrder:view")
	@RequestMapping(value = "form")
	public String form(HkShopUserOrder hkShopUserOrder, Model model) {
		model.addAttribute("hkShopUserOrder", hkShopUserOrder);
		return "hk/shop/order/hkShopUserOrderForm";
	}

	@RequiresPermissions("shop:order:hkShopUserOrder:edit")
	@RequestMapping(value = "save")
	public String save(HkShopUserOrder hkShopUserOrder, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkShopUserOrder)){
			return form(hkShopUserOrder, model);
		}
		hkShopUserOrderService.save(hkShopUserOrder);
		addMessage(redirectAttributes, "保存用户订单管理成功");
		return "redirect:"+Global.getAdminPath()+"/shop/order/hkShopUserOrder/?repage";
	}
	
	@RequiresPermissions("shop:order:hkShopUserOrder:edit")
	@RequestMapping(value = "delete")
	public String delete(HkShopUserOrder hkShopUserOrder, RedirectAttributes redirectAttributes) {
		hkShopUserOrderService.delete(hkShopUserOrder);
		addMessage(redirectAttributes, "删除用户订单管理成功");
		return "redirect:"+Global.getAdminPath()+"/shop/order/hkShopUserOrder/?repage";
	}

}